import service from '@/api/request'
import type { ResTrademarkList, Record, UploadResponse } from './trademark.type'

enum TrademarkApi {
  BASE_URL = '/admin/product/baseTrademark',
  CREATE_URL = '/admin/product/baseTrademark/save',
  UPDATE_URL = '/admin/product/baseTrademark/update',
  UPLOAD_URL = '/admin/product/fileUpload',
  DELETE_URL = '/admin/product/baseTrademark/remove',
  BATCH_DELETE_URL = '/admin/product/baseTrademark/batchRemove',
}

/**
 * 图片上传响应接口
 */


const trademarkApi = {
  getList: (page: number, size: number) => service.get<ResTrademarkList>(TrademarkApi.BASE_URL + `/${page}/${size}`),
  create: (data: Record) => service.post(TrademarkApi.CREATE_URL, data),
  update: (data: Record) => service.put(TrademarkApi.UPDATE_URL, data),
  // 上传图片文件
  uploadLogo: (file: File): Promise<{ data: UploadResponse }> => {
    const formData = new FormData()
    formData.append('file', file)

    return service.post<UploadResponse>(TrademarkApi.UPLOAD_URL, formData, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },
  // 删除品牌
  delete: (id: string) => service.delete(TrademarkApi.DELETE_URL + `/${id}`),
  // 批量删除品牌
  batchDelete: (ids: string[]) => service.delete(TrademarkApi.BATCH_DELETE_URL, { data: ids }),
}

export default trademarkApi
